const path = require('path'); // node自带的模块，无需安装
const HtmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin')
module.exports = {
  entry: {
    app: './src/index.js'
  },
  output: {
    path: path.join(__dirname, '/dist'),
    // filename: 'bundle.js'
    // filename: '[name].js'
    filename: '[name].[hash:8].js'
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      template: './public/index.html', // 打包的html文件的路径
      // title: 'webpack', // 没有模板时自动插入index.html文件，自动添加title
      filename: 'index.html', // 打包后的文件的名称
      hash: true,
      cache: false,
      minify: {
        removeAttributeQuotes: true,
        removeComments: true,
        // removeEmptyElements: true // 一般不敢随意配置
      }
    })
  ],
  module: {
    rules: [
      {
        test: /\.css$/,
        loader: "style-loader!css-loader"
      },
      {
        test: /\.scss$/,
        loader: "style-loader!css-loader!sass-loader"
      },
      {
        test: /\.less$/,
        loader: "style-loader!css-loader!less-loader"
      },
      {
        test: /\.js$/,
        loader: 'babel-loader'
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.(png|jpg|jpeg|gif|webp|svg)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 102400,
              outputPath: 'img'
            }
          }
        ]
      }
    ]
  },
  devServer: {
    port: 8989,
    open: true,
    proxy: { // 配置反向代理，解决跨域问题
      '/daxun': {
        target: 'http://nz1908.wudaxun.top/api',
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/daxun': ''
        }
      }
    }
  },
  devtool: 'source-map' // 方便断点调试代码 - 浏览器 - 控制台- sources
}